package com.yantong.controller.statistics;

import com.yantong.controller.BaseController;
import com.yantong.pojo.bo.PrdStaticDataReqDto;
import com.yantong.pojo.vo.ProdAfterSaleVo;
import com.yantong.service.ProductStaticService;
import com.yantong.utils.DateUtils;
import com.yantong.utils.PageUtils;
import com.yantong.utils.excel.ExcelHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/prod/aftersalestatic")
public class ProductStaticsController extends BaseController {
	
	private static final String prefix = "report";
	private static final Logger logger = LoggerFactory.getLogger(ReportController.class);
	@Autowired
	private ProductStaticService productStaticService;


	
	@GetMapping("/prodstaticData")
	@ResponseBody
	@RequiresPermissions("report:manage:productSale")
	public PageUtils<ProdAfterSaleVo> prodstaticData (PrdStaticDataReqDto reqDto) {
		return productStaticService.prodstaticData(reqDto);
	}
	
	
	
	@RequiresPermissions(value = {"report:manage:export"})
    @GetMapping("/export")
    public void exportProdAfterSal(PrdStaticDataReqDto reqDto, HttpServletResponse response) {
        List<List<Object>> resultData = new ArrayList<>();
        String[] head = {"商品ID", "商品名称", "商品规格", "销售数量", "成本价","单价","销售金额","售后数量","售后总金额","平台销售总额",
                        "售后总额","平台售后率","商品售后率","差异","供应商"};
        resultData.add(0, Arrays.asList(head));
        resultData  = productStaticService.excelData(reqDto,resultData);
        String fileName = "订单记录_" + DateUtils.format(new Date(), "yyyyMMddHHmmss");
        try {
            ExcelHelper.exportExcel(response, fileName, "订单记录", resultData);
        } catch (IOException e) {
            logger.info("export order list error:{}", e.getMessage());
        }
    }

}
